<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
namespace app\common;

use think\exception\Handle;
class ApiHandleException extends Handle
{
    /**
     * http状态码
     * @var unknown
     */
    public $httpCode = 500;

    public function render(\Exception $e)
    {
        $file=$e->getFile();
        $line=$e->getLine();
        return $this->show(0, $e->getMessage(), [], $this->httpCode);
    }

    function show($status, $message ,$data = [] ,$httpCode = 200)
    {
        $data =  [
            'code' => $httpCode,
            'error' => $message,
            'data' =>$data
        ];

        return json($data, $httpCode);

    }
}